package edu.suda.xsap.controller;

import edu.suda.xsap.common.Result;
import edu.suda.xsap.entity.ChartData;
import edu.suda.xsap.service.ChartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/chart")
@Slf4j
public class ChartController {
    @Autowired
    private ChartService chartService;

    @GetMapping("/cardList")
    public Result getCardData() {
        try {
            List<ChartData> data = chartService.getCardData();
            return Result.success(data);
        } catch (Exception e) {
            log.error("查询失败", e);
            return Result.failure(e.getMessage(), e);
        }
    }
    @GetMapping("/costList")
    public Result getCostData() {
        try {
            List<ChartData> data = chartService.getCostData();
            return Result.success(data);
        } catch (Exception e) {
            log.error("查询失败", e);
            return Result.failure(e.getMessage(), e);
        }
    }
    @GetMapping("/courseCostList")
    public Result getCourseCostData() {
        try {
            List<ChartData> data = chartService.getCourseCostData();
            return Result.success(data);
        } catch (Exception e) {
            log.error("查询失败", e);
            return Result.failure(e.getMessage(), e);
        }
    }
}
